package org.hackystat.devcathlon.ui.page.teams.invitations;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.engine.team.TeamManager;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.login.LoginPage;
import org.junit.Test;

/**
 * Test classes for the TeamsInvitationPage. 
 *
 * @author John Ly
 *
 */

public class TestTeamsInvitationPage extends DevcathlonTestHelper { 
  
  private String user = "member1@hackystat.org";
  private String teamName = "Your1stTeam";
  /**
   * Tests the TeamsInvitation page for display information.
   * @throws Exception If there is a bug.
   */
  @Test
  public void testTeamsManagePage() throws Exception {
    WicketTester tester = new WicketTester(new DevcathlonApplication());

    makeTeamAndInvites(teamName, "admin", "member1", "member2");
    
    TeamManager.getInstance().getTeam(teamName).setProjectName("Default");
    TeamManager.getInstance().getTeam(teamName).setDescription("Hello");
    TeamManager.getInstance().getTeam(teamName).setTeamLogoPath("Team1.png");
    
    tester.startPage(TeamsInvitationPage.class);
    tester.assertRenderedPage(LoginPage.class);    
    
    // Fill out the login form.
    FormTester formTester = tester.newFormTester("loginForm");
    formTester.setValue("user", user);
    formTester.setValue("password", user);
    formTester.submit();
    
    ((DevcathlonSession)tester.getWicketSession()).getTeamsSession().setSelectedTeam(teamName);
            
    tester.assertRenderedPage(TeamsInvitationPage.class);
    
    assertNull("wicket ID form not found.", tester.getTagByWicketId("InvitationsForm"));
    assertNotNull("wicket ID form found.", tester.getTagByWicketId("InviteForm"));
    
    tester.assertContains(teamName);
    
  }
  
  
  
}
